package org.jenijo.querydroid;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.jenijo.querydroid.model.QCM;

public class QCMAdapter extends BaseAdapter {
	private ArrayList<QCM> list;
	private LayoutInflater inflater;
	
	public QCMAdapter(Context context, ArrayList<QCM> list){
		inflater = LayoutInflater.from(context);
		this.list=list;
	}
	

	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0).getId();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView==null){
			holder=new ViewHolder();
			convertView=inflater.inflate(R.layout.qcmitem, null);
			holder.tvTitre = (TextView)convertView.findViewById(R.id.tvTitre);
			holder.tvName = (TextView)convertView.findViewById(R.id.tvName);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
		holder.tvTitre.setText(list.get(position).getTitre());
		holder.tvName.setText(list.get(position).getAuthor());
		return convertView;
	}
	private class ViewHolder{
		TextView tvTitre;
		TextView tvName;
	}
}
